package primary.primary0;

import java.util.HashMap;
import java.util.Map;

public class S0001两数之和 {
    /**
     * 77
     * hash表
     */
    class Solution {
        public int[] twoSum(int[] nums, int target) {
            Map<Integer, Integer> record = new HashMap<>();
            for(int i = 0; i < nums.length; i++){
                if(record.containsKey(target - nums[i])){
                    return new int[]{i, record.get(target - nums[i])};
                }
                record.put(nums[i], i);
            }
            return null;
        }
    }
}
